export default {
  methods: {

    /**
     * 随机生成方块的逻辑
     *    先判断可生成方块的位置
     *    再随机生成
     */
    createRandomBlock (list) {
      const emptyList = []
      list.forEach((item, row) => {
        item.forEach((block, col) => {
          if (block === 0) {
            emptyList.push([row, col])
          }
        })
      })
      const obj = this.randomBlock(emptyList)
      const coordinate = obj.Coordinate
      list[coordinate[0]][coordinate[1]] = obj.Value
    },
    randomCoordinate (emptyList) {
      const coordinate = Math.floor(Math.random() * emptyList.length)
      return emptyList[coordinate]
    },
    randomValue () {
      const _r = Math.random()
      if (_r < 0.614) {
        return 2
      } else {
        return 4
      }
    },
    randomBlock (emptyList) {
      const obj = {}
      obj.Coordinate = this.randomCoordinate(emptyList)
      obj.Value = this.randomValue()
      return obj
    }
  }
}
